home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 115
/
FreelogNo115-MaiJuin2013.iso
/
Internet
/
AvantBrowser
/
asetup.exe
/
_data
/
webkit
/
chrome_100_percent.pak
/
Unnamed File 000013.txt
< prev
next >
Wrap
Text File
|
2013-04-03
|
885b
|
28 lines
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Expose a function to watch the HTML tag creation via Mutation Observers.
function watchForTag(tagName, cb) {
// Query tags already in the document.
var nodes = document.body.querySelectorAll(tagName);
for (var i = 0, node; node = nodes[i]; i++) {
cb(node);
}
// Observe the tags added later.
var documentObserver = new WebKitMutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
for (var i = 0, addedNode; addedNode = mutation.addedNodes[i]; i++) {
if (addedNode.tagName == tagName) {
cb(addedNode);
}
}
});
});
documentObserver.observe(document, {subtree: true, childList: true});
}
exports.watchForTag = watchForTag;